{% extends "../layouts/admin.html" %} {% block content %}
<header class="header navbar bg-white shadow">
	<div class="btn-group tool-button">
		<a class="btn btn-primary navbar-btn" href="/store/coupon/index" data-pjax><i class="ti-angle-left"></i> 返回</a>
	</div>
</header>

<div class="content-wrap">
	<div class="wrapper" style="min-height:500px;">
		<section class="panel panel-form">
			<form id="addForm" role="form" class="form-horizontal parsley-form" data-parsley-validate action="/store/coupon/edit" method="post">
				<div class="row mb10">
					<input type="hidden" id="id" name="id" value="{{coupon.id}}">
					<div class="col-lg-12">
						<div class="form-group">
							<label for="name" class="col-sm-2 control-label">优惠券名称</label>

							<div class="col-sm-8">
								<input type="text" id="name" class="form-control" name="name" data-parsley-required="true" placeholder="优惠券名称" value="{{coupon.name}}">
							</div>
						</div>
						<div class="form-group">
							<label for="money" class="col-sm-2 control-label">优惠券金额</label>

							<div class="col-sm-8">
								<input type="text" id="money" class="form-control" name="money" value="{{coupon.money}}" data-parsley-required="true" placeholder="优惠券金额">
							</div>
						</div>
						<div class="form-group">
							<label class="col-sm-2 control-label">类型</label>

							<div class="col-sm-8">
								

								<select class="form-control" name="type">
									<option value="" disabled selected>类型</option>
									{% for index,item in config.setup.couponType %}
									<option value="{{index}}" {%if index == coupon.type%}selected{%endif%}>{{item}}</option>
									{% endfor %}
								</select>

							</div>
						</div>
						<div class="form-group" style="display: none;">
							<label for="min_amount" class="col-sm-2 control-label">发放订单金额下限</label>

							<div class="col-sm-8">
								<input type="text" id="min_amount" class="form-control" name="min_amount" value="{{coupon.min_amount}}" data-parsley-required="false" placeholder="发放订单金额下限">
							</div>
						</div>
						<div class="form-group">
							<label for="min_goods_amount" class="col-sm-2 control-label">最小订单金额</label>

							<div class="col-sm-8">
								<input type="text" id="min_goods_amount" class="form-control" name="min_goods_amount"  value="{{coupon.min_goods_amount}}"  data-parsley-required="true" placeholder="使用最小订单金额">
							</div>
						</div>
						
						<div class="form-group">
							<label for="send_start_date" class="col-sm-2 control-label">发放开始日期</label>

							<div class="col-sm-8">
								<input type="text" id="send_start_date" class="form-control date" name="send_start_date"  value="{{coupon.send_start_date | format}}" data-parsley-required="true" placeholder="发放开始日期">
							</div>
						</div>
						<div class="form-group">
							<label for="send_end_date" class="col-sm-2 control-label">发放结束日期</label>

							<div class="col-sm-8">
								<input type="text" id="send_end_date" class="form-control date" name="send_end_date"  value="{{coupon.send_end_date | format}}" data-parsley-required="true" placeholder="发放结束日期">
							</div>
						</div>
						<div class="form-group">
							<label for="use_start_date" class="col-sm-2 control-label">使用开始日期</label>

							<div class="col-sm-8">
								<input type="text" id="use_start_date" class="form-control date" name="use_start_date"  value="{{coupon.use_start_date | format}}" data-parsley-required="true" placeholder="使用开始日期">
							</div>
						</div>
						<div class="form-group">
							<label for="use_end_date" class="col-sm-2 control-label">使用结束日期</label>

							<div class="col-sm-8">
								<input type="text" id="use_end_date" class="form-control date" name="use_end_date"  value="{{coupon.use_end_date | format}}"  data-parsley-required="true" placeholder="使用结束日期">
							</div>
						</div>

						
						
						
					</div>
				</div>
				<div class="col-lg-3"></div>
				<div class="col-lg-6">
					<div class="form-group text-center">
						<label></label>

						<div>
							<button class="btn btn-primary btn-block btn-lg btn-parsley" data-loading-text="正在提交...">提 交</button>
						</div>
					</div>
				</div>
			</form>
		</section>

	</div>
</div>
<script language="JavaScript">
	$(document).ready(function() {
		$("[name=type]").change(function(){
			if($(this).val() == 3){
				$(this).parents(".form-group").next().show();
			}else{
					$(this).parents(".form-group").next().hide();
			}
		});
		$('#addForm').ajaxForm({
			dataType: 'json',
			beforeSubmit: function(arr, form, options) {
				form.find("button:submit").button("loading");
			},
			success: function(data, statusText, xhr, form) {
				if(data.errno == 0) {
					Toast.success(data.data);
					//刷新父级菜单
					//form.resetForm();
				} else {
					Toast.error(data.errmsg);
				}
				form.find("button:submit").button("reset");
			}
		});
		
		lay('.date').each(function(){
laydate.render({
    elem: this
    ,trigger: 'click'
});
}); 
		
	});
</script>
{% endblock %}